import gloabComponentConfig from '/@/settings/gloabComponentConfig';
import { FormSchema } from '/@/components/Form';
import metadata from '/@/settings/metadata';

import { assign } from 'lodash-es';
import { dictArray2Map } from '@/utils/common/compUtils';

export const divider = (option?: Partial<FormSchema>): FormSchema => {
  const _default: FormSchema = {
    field: '-',
    label: option?.label ?? '',
    component: 'Divider',

    colProps: option?.colProps ?? gloabComponentConfig.responseColProps.fullspan,
    componentProps: () => {
      return {
        plain: false,
      };
    },
  };
  return assign(_default, option);
};
/**
 * 用户状态组件
 * @param options
 */
export const userStatusFormItem = (options?: Partial<FormSchema>): FormSchema => {
  const _default: FormSchema = {
    label: '状态',
    field: 'status',
    component: 'Switch',
    componentProps: {
      options: metadata.userStatusData,
      checkedChildren: dictArray2Map(metadata.userStatusData).get(1),
      unCheckedChildren: dictArray2Map(metadata.userStatusData).get(0),
      checkedValue: 1,
      unCheckedValue: 0,
    },
    defaultValue: 1,
  };
  return assign(_default, options);
};
export const userSwitchFormItem = (options?: Partial<FormSchema>): FormSchema => {
  const _default: FormSchema = {
    label: '状态',
    field: 'status',
    component: 'Switch',
    componentProps: {
      options: metadata.userStatusData,
      checkedChildren: dictArray2Map(metadata.userStatusData).get(1),
      unCheckedChildren: dictArray2Map(metadata.userStatusData).get(0),
      checkedValue: 1,
      unCheckedValue: 0,
    },
    defaultValue: 0,
  };

  return assign(_default, options);
};
export const userRemarkFormItem = (options?: Partial<FormSchema>): FormSchema => {
  const _default: FormSchema = {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      autoSize: true,
    },
    rules: [
      {
        max: 200,
      },
    ],
  };
  return assign(_default, options);
};
export const userStatusFormItemSelect = (options?: Partial<FormSchema>): FormSchema => {
  const _default: FormSchema = {
    label: '状态',
    field: 'status',
    component: 'Select',
    componentProps: {
      options: metadata.userStatusData,
    },
  };
  return assign(_default, options);
};

export const userOrderNumFormItem = (options?: Partial<FormSchema>): FormSchema => {
  const _default: FormSchema = {
    label: '排序值',
    field: 'orderNum',
    component: 'InputNumber',
    componentProps: {
      min: 0,
    },
    defaultValue: 0,
  };
  return assign(_default, options);
};

export const userDatePickerFormItem = (options?: Partial<FormSchema>): FormSchema => {
  const _default: FormSchema = {
    label: '日期',
    field: 'date',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  };
  return assign(_default, options);
};
